import {defineStore} from "pinia";
import type {AuthState} from "@/stores/modules/model/auth";
import type {AuthInfo} from "@/api/user/types";
import pinia from "@/stores";

export const useAuthStore = defineStore('app-auth',{
    state:(): AuthState => ({
        // 当前页面的 router name,用来做按钮权限筛选
        routeName: '',
        // 后端返回的用户角色列表
        roles:[],
        // 后端返回的路由列表
        authButtonList:[],
        // 后端返回的路由列表
        authRouterList: [],
        // 处理之后侧边栏菜单列表
        authMenuList: []
    }),
    actions:{
        setRouteName(name: string) {
            this.routeName = name;
        },
        resetAuth(){
            this.authRouterList = [];
        },
        // 设置用户权限信息
        setAuth(authInfo: AuthInfo){
            this.roles = authInfo.roles
            this.authRouterList = authInfo.routes
            this.authButtonList = authInfo.buttons
        },
        setAuthMenuList(list: Menu.MenuOptions[]){
            this.authMenuList = list
        }
    }

})

export const useAuthStoreWithOut = ()=>{
    return useAuthStore(pinia)
}